
#include <BFont>
#include <BStyle>
#include "member_BMessageBox.h"

using namespace BWE;

member_BMessageBox::member_BMessageBox(BMessageBox* messageBox)
{
	boss = messageBox;
	defaultButton = Button_None;
	iconRole = Style_None;
}
member_BMessageBox::~member_BMessageBox()
{

}

const char* member_BMessageBox::buttonText(Button button)
{
	switch (button)
	{
	case BWE::Button_None:
		return "None";
	case BWE::Button_Left:
		return "Left";
	case BWE::Button_Middle:
		return "Middle";
	case BWE::Button_Right:
		return "Right";
	case BWE::Button_Ok:
		return "OK";
	case BWE::Button_Open:
		return "Open";
	case BWE::Button_Save:
		return "Save";
	case BWE::Button_Cancel:
		return "Cancel";
	case BWE::Button_Close:
		return "Close";
	case BWE::Button_Discard:
		return "Discard";
	case BWE::Button_Apply:
		return "Apply";
	case BWE::Button_Reset:
		return "Reset";
	case BWE::Button_Help:
		return "Help";
	case BWE::Button_SaveAll:
		return "SaveAll";
	case BWE::Button_Yes:
		return "Yes";
	case BWE::Button_YesToAll:
		return "YesToAll";
	case BWE::Button_No:
		return "No";
	case BWE::Button_NoToAll:
		return "NoToAll";
	case BWE::Button_Abort:
		return "Abort";
	case BWE::Button_Retry:
		return "Retry";
	case BWE::Button_Ignore:
		return "Ignore";
	default:
		return 0;
	}

}

void member_BMessageBox::freshRects()
{
	const BStyle* style = boss->style();
	if (!style)
		return;

	const BFont* font = style->font();
	if (!font)
		return;

	textSize = font->textSize(text);

	BRect crect = boss->clientRect();
	textRect = crect.align(Align_Center, textSize);
}

void member_BMessageBox::slotButtonClicked(BObject* object)
{
	BButton* button = dynamic_cast<BButton*>(object);
	for (int i = 0; i < buttonPairs.size(); i++)
	{
		if (buttonPairs[i].button == button)
		{
			Button btn = buttonPairs[i].btn;
			boss->done(btn);
			break;
		}
	}
}

